package com.gxa.learning.portal.service.impl;

import com.gxa.learning.core.common.ExceptionCode;
import com.gxa.learning.core.exception.BusinessException;
import com.gxa.learning.core.pojo.Project;
import com.gxa.learning.core.pojo.ProjectDetails;
import com.gxa.learning.core.service.impl.BaseServiceImpl;
import com.gxa.learning.core.util.StringUtil;
import com.gxa.learning.portal.mapper.ProjectDetailsMapper;
import com.gxa.learning.portal.mapper.ProjectMapper;
import com.gxa.learning.portal.service.ProjectDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class ProjectDetailsServiceImpl extends BaseServiceImpl<ProjectDetails> implements ProjectDetailsService {

    @Autowired
    private ProjectDetailsMapper projectDetailsMapper = null;

    @Autowired
    private ProjectMapper projectMapper = null;

    @Override
    public ProjectDetails getById(Long pid) throws BusinessException {
        if (pid == null) {
            throw new BusinessException(ExceptionCode.ARGUMENTS_ERROR);
        }
        ProjectDetails byId = projectDetailsMapper.getById(pid);
        if (byId == null) {
            throw new BusinessException(ExceptionCode.WRONG_DATA);
        }
        return byId;
    }

    @Override
    public List<ProjectDetails> search(String condition) throws BusinessException {
        if (StringUtil.isEmpty(condition)) {
            condition = null;
        }
        List<ProjectDetails> search = projectMapper.search(condition);
        if (search == null) {
            throw new BusinessException(ExceptionCode.WRONG_DATA);
        }
        return search;
    }
}
